﻿using System;
using System.Text;
using System.Security.Cryptography;

namespace XZL.Web.Biz
{
    public class CommonMethods
    {
        /// <summary>
        /// 字符串转MD5
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string StrToMD5(string str)
        {
            if (str != null)
            {
                byte[] data = Encoding.GetEncoding("GB2312").GetBytes(str);
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] OutBytes = md5.ComputeHash(data);

                string OutString = "";
                for (int i = 0; i < OutBytes.Length; i++)
                {
                    OutString += OutBytes[i].ToString("x2");
                }
                return OutString.ToLower();
            }
            else
            {
                return "";
            }
        }
    }
}
